package com.example.a_lambda;

import java.util.Arrays;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;

public class DemoTest1 {
    public static void main(String[] args) {
//        获得数组中的最大值：先排序后返回值
        method(() -> {
            int[] arr = {1, 3, 4, 43, 23, 3};
            Arrays.sort(arr);
            return arr[arr.length - 1];
        });

//        获得字符串的长度
        methodConsumer(s ->
                System.out.println("消费的字符串长度是：" + s.length()), "32343s");

//        将int类型转为string类型字符串
        methodFunction(integer -> integer + "", 23);

        methodPredicate(s -> s.length() == 3, "32#2");
    }

    public static void method(Supplier<Integer> supplier) {
        Integer max = supplier.get();
        System.out.println("最大值是：" + max);
    }

    public static void methodConsumer(Consumer<String> consumer, String s) {
        consumer.accept(s);
    }

    public static void methodFunction(Function<Integer, String> function, Integer i) {
        String str = function.apply(i);
        System.out.println("转换后的字符串是：" + str + 1);
    }

    public static void methodPredicate(Predicate<String> predicate,  String s) {
        boolean test = predicate.test(s);
        System.out.println("测试结果是：" + test);
    }
}
